package com.youi.shop.commons.result;

import lombok.Data;

import java.io.Serializable;

/**
 * @version 1.0
 * @Author: xxf
 * @CreateDate: 2020/11/8 14:39
 */
@Data
public class RespEntity<T> implements Serializable {

    private String message;
    private int status;
    private T date;

    public RespEntity() {
    }

    public RespEntity(T date) {
        this.date = date;
    }

    public RespEntity(StatusCode code, T date) {
        this(code);
        this.date = date;
    }

    public RespEntity(StatusCode code) {
        this.message = code.getMessage();
        this.status = code.getStatus();

    }

    /**
     * @param data
     * @param <T>
     * @return
     */
    public static <T> RespEntity<T> success(T data) {
        return success(StatusCode.SUCCESS, data);
    }

    /**
     * @param code
     * @param data
     * @param <T>
     * @return
     */
    public static <T> RespEntity<T> success(StatusCode code, T data) {
        return new RespEntity<T>(code, data);
    }

    public static <T> RespEntity<T> error() {
        return new RespEntity<T>(StatusCode.SERVICE_ERROR);
    }


    public static <T> RespEntity<T> error(StatusCode code) {
        return error(code, null);
    }

    public static <T> RespEntity<T> error(StatusCode code, T data) {
        return new RespEntity<T>(code, data);
    }

//    public static <T> RespEntity<T> error(String traceId, int retCode, String retMsg) {
//        RespEntity<T> baseResult = new RespEntity<>();
//        baseResult.setRetCode(retCode);
//        baseResult.setRetMsg(retMsg);
//        return baseResult;
//    }


}
